package com.baturu.vin.gm.dal.dao;

import com.baturu.vin.gm.dal.entity.GroupDescEntity;
import com.baturu.vin.gm.dal.entity.SubjectDescEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
 * @Author: chenjiahao
 * @Time: 2019/11/5
 */
public interface GMGroupDAO {

    @Select({"SELECT catalog_code,group_code,description_cn,description_en FROM gm_epc_cd_groupdesc WHERE catalog_code = #{catalog}"})
    List<GroupDescEntity> queryMGroupByCatalog(@Param("catalog") String catalog);

    @Select({"SELECT subject,Description_CN FROM gm_epc_cd_partmain",
            "WHERE catalog_code = #{catalog} AND Group_code = #{mainGroupCode}",
            "ORDER BY SUBJECT"
    })
    List<SubjectDescEntity> querySubGroupByMGAndCatalog(@Param("catalog") String catalog, @Param("mainGroupCode") String mainGroupCode);

    @Select({"<script>SELECT subject,Description_CN,group_code FROM gm_epc_cd_partmain",
            "WHERE catalog_code = #{catalog} ",
            "AND subject in " ,
            "<foreach item='item' index='index' collection='subjects' open='(' separator=',' close=')'>" ,
            "#{item}",
            "</foreach></script>"
    })
    List<SubjectDescEntity> querySubGroupByPartsAndCatalog(@Param("catalog") String catalog, @Param("subjects") Collection<String> subject);

    @Select({"<script>SELECT catalog_code,group_code,description_cn,description_en FROM gm_epc_cd_groupdesc WHERE catalog_code = #{catalog}",
            "AND group_code in " ,
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>" ,
            "#{item}",
            "</foreach></script>"
    })
    List<GroupDescEntity> queryMGroupByCatalogAndGroup(@Param("catalog") String catalog, @Param("codes") Collection<String> groupCodes);
}
